<h1>Facebook Insights</h1>
<table>
    <tr>
        <td>Seleccione una de sus cuentas</td>
        <td>
            <select id="account" name="account">
                <option value="">Seleccione</option>
              <?php foreach($accounts['data'] as $account){ ?>
                <option value="<?php echo $account['id']; ?>">
                    <?php echo $account['name']; ?></option>
              <?php } ?>
            </select>
        </td>
    </tr>
    <tr>
        <td>Metrica</td>
        <td>
            <select id="metric" name="metric">
                <option value="">Seleccione</option>
                <option value="application_active_users">
                    application_active_users</option>
            </select>
        </td>
    </tr>
    <tr>
        <td>Tiempo de término</td>
        <td>
            <input type="text" id="end_date" name="end_date" value="2012-08-06" />
            (*) Formato: año-mes-dia [2012-08-06]
        </td>
    </tr>
    <tr>
        <td>Periodo</td>
        <td>
            <select id="period" name="period">
                <option value="">Seleccione</option>
                <option value="day">Dia</option>
                <option value="month">Mes</option>
            </select>
        </td>
    </tr>
    <tr>
        <td colspan="2" align="center">
            <input type="submit" value="Consultar" onclick="ajax_search();" />
        </td>
    </tr>
</table>
<div id="results"></div>
<script type="text/javascript">
function ajax_search(){
    var account = $("#account").val();
    var metric = $("#metric").val();
    var end_date = $("#end_date").val();
    var period = $("#period").val();
    $("#results").html("Cargando ...");
    $.ajax({
        type: "post",
        url: "<?php echo url_for('@ajax_facebook_insights_search') ?>",
        data: "account="+account+"&metric="+metric+"&end_date="+end_date+"&period="+period,
        success: function(html){
            $("#results").html(html);
        }
    });
}
</script>